import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by Administrator on 2017/5/17 0017.
 */

public class MyDatabaseHelper extends SQLiteOpenHelper {
    public static final String CREATE_SCORE = "create table MAXScore(" +
            "score_id char(10) not null)";

    private Context mContext;

    public  MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
        super(context,name,factory,version);
        mContext=context;
    }

    public  void onCreate(SQLiteDatabase db){
        db.execSQL(CREATE_SCORE);
        db.execSQL("INSERT INTO MAXScore VALUES('0')");
//        Toast.makeText(mContext,"创建数据库成功",Toast.LENGTH_SHORT).show();
    }

    //插入
    public void Insert(SQLiteDatabase db,String s){
        String SQL = "INSERT INTO MAXScore VALUES('"+s+"')";
        db.execSQL(SQL);
    }

    //查询
    public String query(SQLiteDatabase db){
        Cursor cursor = db.query("MAXScore",null,null,null,null,null,null);
        cursor.moveToFirst();
        String Score = cursor.getString(cursor.getColumnIndex("score_id"));
        return Score;
    }

    //更新
    public void Update(SQLiteDatabase db,String s1,String s2){
        ContentValues values = new ContentValues();
        values.put("score_id",s1);
        db.update("MAXScore",values,"score_id=?",new String[]{s2});
    }
    public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){

    }
}